import socket
from utils import log


def run(host,port):
    print('start at', '{}:{}'.format(host,port))
    with socket.socket as s:
        s.bind((host,port))
        while True:
            s.listen(5)
            connection,adress = s.accept()
            r = connection(1024)
            r = r.decode('utf-8')
            path = r.split()[1]
            method = r.split()[0]
            body = r.split('\r\n\r\n', 1)[1]
            response = response_for_path(path)
            connection.sendall(response)
            connection.close()


if __name__ == '__main__':
    run('127.0.0.1',3000)